package com.lft.com.oilgas.controller;

import com.lft.com.oilgas.entity.Accounts;
import com.lft.com.oilgas.entity.Commodity;
import com.lft.com.oilgas.service.IAccountsSerice;
import com.lft.com.oilgas.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@Transactional
@RequestMapping("/util/accounts")
public class AccountsController {
    @Autowired
    private IAccountsSerice iAccountsSerice;
    @ExceptionHandler(Exception.class)
    public Result xx(Exception ex) {
        //noinspection CallToPrintStackTrace
        ex.printStackTrace();
        return new Result(false, "服务器异常，等会再试");
    }
    @RequestMapping("/insterUpdateAccounts")
    public Result InsterOrUpdateAccounts(@RequestBody Accounts accounts) {
        return new Result(true, iAccountsSerice.insertOrUpdateacc(accounts));
    }
    //修改或者增加
    @Transactional
    @RequestMapping("/gaiorzeng")
    public Result zengorgai(@RequestBody Accounts accounts) {
        System.out.println(accounts);
        iAccountsSerice.insertOrUpdate(accounts);
        return new Result(true, null);
    }

    //查询详情
    @RequestMapping("/kaihuxq/{id}")
    public  Result selectByid(@PathVariable("id")  Integer id){
        Accounts accounts = iAccountsSerice.selectByid(id);
        return new Result(true,accounts);
    }
}
